package exam;

/**
 * Tests the answer to the first array question.
 * The text of the question is as follows:
 * "Write a method that swaps the element at index first of the array and the element at index 
 *  second of the array.  If either index is outside the bounds of the array, then throw an 
 *  IllegalArgumentException."
 * 
 * @author Branden Ogata
 *
 */

public class TestArrayA00 extends Tester
{
  public static void main(String[] args)
  {
    final double points = getPoints(args);
    
    ArrayA00 question = new ArrayA00();
    int[] integers = new int[] {7, 5, 28, 1, 7, 0, 25, 4, 11, 25, 0, 36, 5, 0, 236};
    
    question.swap(integers, 5, 8);
    System.out.println(test(Category.EQUALS, "swap(integers, 5, 8); integers[5]:", 11, 
                            integers[5], percentageToPoints(EIGHTH, points)));
    System.out.println(test(Category.EQUALS, "swap(integers, 5, 8); integers[8]:", 0, 
                            integers[8], percentageToPoints(EIGHTH, points)));
    
    question.swap(integers, 14, 0);
    System.out.println(test(Category.EQUALS, "swap(integers, 14, 0); integers[0]:", 236, 
                            integers[0], percentageToPoints(EIGHTH, points)));
    System.out.println(test(Category.EQUALS, "swap(integers, 14, 0); integers[14]:", 7, 
                            integers[14], percentageToPoints(EIGHTH, points)));    
    
    boolean threwException = false;
    
    try
    {
      question.swap(integers, -1, 4);
    }
    catch (IllegalArgumentException e)
    {
      threwException = true;
    }
    finally
    {
      System.out.println(test(Category.EQUALS, "swap(integers, -1, 4) throws " + 
                                               "IllegalArgumentException", true, threwException, 
                              percentageToPoints(SIXTH, points)));
    }
    
    threwException = false;
    
    try
    {
      question.swap(integers, 6, 16);
    }
    catch (IllegalArgumentException e)
    {
      threwException = true;
    }
    finally
    {
      System.out.println(test(Category.EQUALS, "swap(integers, 6, 16) throws " + 
                                               "IllegalArgumentException", true, threwException, 
                              percentageToPoints(SIXTH, points)));
    }    
    
    threwException = false;
    
    try
    {
      question.swap(integers, 25, -10);
    }
    catch (IllegalArgumentException e)
    {
      threwException = true;
    }
    finally
    {
      System.out.println(test(Category.EQUALS, "swap(integers, 25, -10) throws " + 
                                               "IllegalArgumentException", true, threwException, 
                              percentageToPoints(SIXTH, points)));
    }
    
    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), points);
  }
}
